import 'package:flutter/material.dart';
import 'package:flutter_2b_client/json/LocalDateConverter.dart';
import 'package:flutter_2b_client/utils/local_datetime.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'NullableLocalDateRange.g.dart';

part 'NullableLocalDateRange.freezed.dart';

@freezed
class NullableLocalDateRange with _$NullableLocalDateRange {
  const factory NullableLocalDateRange({
    @LocalDateConverter() LocalDate? start,
    @LocalDateConverter() LocalDate? end,
  }) = _NullableLocalDateRange;

  const NullableLocalDateRange._();

  factory NullableLocalDateRange.fromJson(Map<String, dynamic> json) =>
      _$NullableLocalDateRangeFromJson(json);

  DateTimeRange? toDateTimeRangeOrNull() {
    if (start == null || end == null) {
      return null;
    }
    return DateTimeRange(start: start!.date, end: end!.date);
  }
}
